package followme.yaohuile.com.followme.adapter.recommend.community;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.List;

import followme.yaohuile.com.followme.R;
import followme.yaohuile.com.followme.bean.recommend.community.CommunityForum_listGroups;
import followme.yaohuile.com.followme.network.recommend.NetWork;

/**
 * Created by Lenovo on 2015/11/14.
 */
public class CommunityMianAdapter extends BaseAdapter {
    private List<CommunityForum_listGroups> datas;
    private Context context;
    private  boolean flag = false;
    private int size=0;

    public CommunityMianAdapter(List<CommunityForum_listGroups> datas, Context context) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (datas != null) {
            ret = datas.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View ret = null;

        if (convertView != null) {
            ret = convertView;
        } else {
            LayoutInflater inflater = LayoutInflater.from(context);
            ret = inflater.inflate(R.layout.community_item_gv, parent, false);

            ViewHolder holder = (ViewHolder) ret.getTag();
            if (holder == null) {
                holder = new ViewHolder();
                holder.community_item_icon = (ImageView) ret.findViewById(R.id.community_item_icon);
                holder.community_item_name = (TextView) ret.findViewById(R.id.community_item_name);
                holder.communty_item_total_threads = (TextView) ret.findViewById(R.id.communty_item_total_threads);
                holder.community_item_GroupName = (TextView) ret.findViewById(R.id.community_item_GroupName);
                holder.community_item_line = (TextView) ret.findViewById(R.id.community_item_line);
                ret.setTag(holder);
            }

//            CommunityForum_list forum_list = datas.get(position);
//            List<CommunityForum_listGroups> groups = forum_list.getGroup();

//            判断每一个group的groups_item 项是不是加载完，若加载完或者是刚开始，就把flag设为true；
//            if (size==0||size==groups.size()){
//                flag=true;
//            }
////            当flag为true时，让显示forum_list的name的TextView和分割线显示，并给设置相应的值
//            if (flag){
//                holder.community_item_GroupName.setVisibility(View.VISIBLE);
//                holder.community_item_line.setVisibility(View.VISIBLE);
//            }
//            holder.community_item_GroupName.setText(forum_list.getName());
            for (int i = 0; i <datas.size() ; i++) {
                holder.community_item_name.setText(datas.get(position).getName());
                holder.communty_item_total_threads.setText(datas.get(position).getTotal_threads()+"个主题");
//                TODO 设置图片
                String icon_url=datas.get(position).getPhoto();
                NetWork.getImage(holder.community_item_icon, icon_url, context);
            }

        }
        return ret;
    }
    public static class ViewHolder {
       public  ImageView community_item_icon;
       public TextView community_item_name, communty_item_total_threads, community_item_GroupName, community_item_line;
    }
}
